package com.example.news.fragment;

import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.MediaController;
import android.widget.VideoView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import com.example.news.R;

public class ShipinActivity extends AppCompatActivity implements View.OnClickListener {
    VideoView videoView;
    MediaController mediaController;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.shiping);
        Toolbar toolbar=findViewById(R.id.shipin_toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        Intent i=getIntent();
        String url=i.getStringExtra("video");
        videoView = findViewById(R.id.videoView);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
//            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }
        videoView.setVideoURI(Uri.parse(url));
        mediaController=new MediaController(this);
        videoView.setMediaController(mediaController);
        videoView.start();
        videoView.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if(videoView!=null && videoView.isPlaying()){
            videoView.stopPlayback();
        }else{
            videoView.start();
        }

    }

    @Override
    public void onPointerCaptureChanged(boolean hasCapture) {

    }
}
